#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;

int n, m;
int a[N], b[N];
ll ans;
void merge(int l, int mid, int r) {
  int i = l, j = mid + 1, k = l;
  while (i <= mid && j <= r) {
    if (a[i] <= a[j])
      b[k++] = a[i++];
    else
      ans += mid + 1 - i, b[k++] = a[j++];
  }
  while (i <= mid) b[k++] = a[i++];
  while (j <= r) b[k++] = a[j++];
  rep(i, l, r) a[i] = b[i];
}
void merge_sort(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  ll res = 0;
  merge_sort(l, mid);
  merge_sort(mid + 1, r);
  merge(l, mid, r);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while ((cin >> n) && n) {
    rep(i, 1, n) cin >> a[i];
    ans = 0;
    merge_sort(1, n);
    cout << ans << endl;
  }
  return 0;
}